//
// Created by dcang on 2021/7/12.
//

#ifndef NDKDEMO_YCFFMPEG_H
#define NDKDEMO_YCFFMPEG_H

#include "AndroidLog.h"
#include "pthread.h"
#include "YcBasePlayer.h"
#include "YcJavaCall.h"
#include "YcAudio.h"
#include "YcVideo.h"
#include "YcPlayStatus.h"
#include "YcAudioChannel.h"

extern "C"
{
#include <libavformat/avformat.h>
}


class YcFFmpeg {
public:
    const char *urlpath = NULL;
    YcJavaCall *ycJavaCall = NULL;
    pthread_t decodThread;
    AVFormatContext *pFormatCtx = NULL;//封装格式上下文
    int duration = 0;
    YcAudio *ycAudio = NULL;
    YcVideo *ycVideo = NULL;
    YcPlayStatus *ycPlayStatus = NULL;
    bool exit = false;
    bool exitByUser = false;
    int mimeType = 1;
    bool isavi = false;
    bool isOnlyMusic = false;

    std::deque<YcAudioChannel*> audiochannels;
    std::deque<YcAudioChannel*> videochannels;

    pthread_mutex_t init_mutex;
    pthread_mutex_t seek_mutex;

public:
    YcFFmpeg(YcJavaCall *javaCall, const char *urlpath, bool onlymusic);
    ~YcFFmpeg();
    int preparedFFmpeg();
    int decodeFFmpeg();
    int start();
    int seek(int64_t sec);
    int getDuration();
    int getAvCodecContext(AVCodecParameters * parameters, YcBasePlayer *wlBasePlayer);
    void release();
    void pause();
    void resume();
    int getMimeType(const char* codecName);
    void setAudioChannel(int id);
    void setVideoChannel(int id);
    int getAudioChannels();
    int getVideoWidth();
    int getVideoHeight();
};


#endif //NDKDEMO_YCFFMPEG_H
